/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tableview;

import data.Employees;
import java.util.ArrayList;
import java.util.List;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author Hùng
 */
public class EmployeeTableView extends AbstractTableModel {

    List<Employees> lEmployees;

    public EmployeeTableView() {
        this(new ArrayList<Employees>());
    }

    public EmployeeTableView(List<Employees> lEmployees) {
        this.lEmployees = lEmployees;
    }

    public List<Employees> getlEmployees() {
        return lEmployees;
    }

    public void setlEmployees(List<Employees> lEmployees) {
        this.lEmployees = lEmployees;
    }

    @Override
    public int getRowCount() {
        if (lEmployees != null) {
            return this.lEmployees.size();
        }
        return 0;
    }

    @Override
    public int getColumnCount() {
        return 7;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Object value = null;

        Employees tmpE = this.lEmployees.get(rowIndex);

        switch (columnIndex) {
            case 0: {
                value = tmpE.getEmpid();
                break;
            }
            case 1: {
                value = tmpE.getEname();
                break;
            }
            case 2: {
                value = tmpE.getUsername();
                break;
            }
            case 3: {
                value = tmpE.getDeptno();
                break;
            }
            case 4: {
                if (tmpE.getSections() != null) {
                    value = tmpE.getSections().getSectname();
                }

                break;
            }
            case 5: {
                value = tmpE.getDesignation().getDesignation();
                break;
            }
            case 6: {
                value = tmpE.getRole();
                break;
            }
        }
        return value;
    }

    @Override
    public String getColumnName(int column) {
        String value = "";
        switch (column) {
            case 0: {
                value = "IDEmployee";
                break;
            }
            case 1: {
                value = "NameEmployee";
                break;
            }
            case 2: {
                value = "UserName";
                break;
            }
            case 3: {
                value = "Department";
                break;
            }
            case 4: {
                value = "Section";
                break;
            }
            case 5: {
                value = "Designation";
                break;
            }
            case 6: {
                value = "Role";
                break;
            }
        }
        return value;
    }
//    public List<String> removeEmployees(int[] index,TableModel model) {
//        List<String> tmpIdE = new ArrayList<String>();
//        for (int i = 0 ; i < index.length;i++ ) {
//            tmpIdE.add((String) model.getValueAt(i, 0));
//            fireTableRowsDeleted(i, i);
//        }
//        return tmpIdE;
//    }
}
